package com.hawk.eye.framework.plugins.webhook;

import com.hawk.eye.api.webhook.IWebhookRequester;
import com.hawk.eye.framework.exception.HawkEyeWebhookIdRepeatException;
import com.hawk.eye.framework.utils.ExceptionAssert;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @className: WebhookFactory
 * @description:
 * @author: salad
 * @date: 2023/10/4
 **/
public class WebhookFactory {

    private final ConcurrentHashMap<String, IWebhookRequester> webhooks = new ConcurrentHashMap<>();


    public IWebhookRequester get(String type) {
        return webhooks.get(type);
    }

    public void add(IWebhookRequester webhookRequester) {
        ExceptionAssert.isNotEmptyThrow(get(webhookRequester.identity()),
                () -> new HawkEyeWebhookIdRepeatException("webhook[" + webhookRequester.identity() + "]已经存在"));
        webhooks.put(webhookRequester.identity(), webhookRequester);
    }

    public ConcurrentHashMap<String, IWebhookRequester> getWebhooks() {
        return webhooks;
    }

}
